#include<updatefile.h>


bool UpdateFile::createFile(QString shiyanID)
{
    time_t timep;
    char name[256] = {0};

    QString dir = QCoreApplication::applicationDirPath();
    dir = dir +"/logs/";

    time(&timep);//获取从1970至今过了多少秒，存入time_t类型的timep

    strftime(name, sizeof(name), "%Y.%m.%d_log.txt",localtime(&timep) ); //最后一个参数是用localtime将秒数转化为struct tm结构体
    string filename = shiyanID.toStdString() + "_"+string(name);

    string path = dir.toStdString() + filename;

    QFile qfile(QString::fromStdString(path));

    if (! qfile.exists(QString::fromStdString(path)))
    {

        if(qfile.open( QIODevice::ReadWrite | QIODevice::Text))
        {
            qfile.close();
            return true;
        }
        else
        {
            qfile.close();
            return false;
        }

    }

    return true;

}

QString UpdateFile::getDir(QString shiyanID)
{
    time_t timep;
    char name[256] = {0};
    QString dir = QCoreApplication::applicationDirPath();
    dir = dir +"/logs/";

    time(&timep);

    strftime(name, sizeof(name), "%Y.%m.%d_log.txt",localtime(&timep) );
    string filename = shiyanID.toStdString() + "_"+string(name);

    QString path = dir + QString::fromStdString(filename);

    return path;
}
